﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "UiCustom/Mirror"
{
	Properties
	{
		_RefTex("Reflection Textrue", 2D) = "white" {}
	}

	SubShader
		{
			Tags{ "Queue" = "Transparent" }
			Pass
			{
				Tags{ "LightMode" = "ForwardBase" }
				ZWrite Off
				Blend SrcAlpha OneMinusSrcAlpha

				CGPROGRAM
				#pragma vertex vert  
				#pragma fragment frag

				#include "UnityCG.cginc"

				sampler2D _RefTex;

				struct a2v
				{
					float4 vertex : POSITION;
					float3 texcoord : TEXCOORD0;
				};

				struct v2f
				{
					float4 pos : SV_POSITION;
					float2 uv_ref : TEXCOORD0;
				};

				v2f vert(a2v v)
				{
					v2f o;
					o.pos = UnityObjectToClipPos(v.vertex);

					//计算该模型顶点在屏幕坐标的纹理信息
					float4 screenUV = ComputeScreenPos(o.pos);
					o.uv_ref = screenUV.xy / screenUV.w;
					
					return o;
				}

				fixed4 frag(v2f i) : SV_Target
				{
					return tex2D(_RefTex, i.uv_ref);
				}
				ENDCG
			}
		}
		FallBack "Specular"
}